<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组去重</title>
</head>
<body>
    <div id="result"></div>

    <script>
        var arr = [1, 2, 3, 4, 2, 5, 6, 2, 7, 2];
        var array = [4, 6, 0, 3, 0, 0, 0, 1,3];
        function remove(arr, num) {
            return arr.filter(function(element) {
                return element !== num;
            });
        }
        function removeZero(array) {
            var newArray = [];
            
            for (var i = 0; i < array.length; i++) {
                if (array[i] !== 0) {
                    newArray.push(array[i]);
                }
            }
            
            return newArray;
        }
        var newArray1 = remove(arr, 2);
        var newArray2 = removeZero(array);
        console.log("1, 2, 3, 4, 2, 5, 6, 2, 7, 2");
        console.log("需求分析1题计算结果:", newArray1);
        console.log("4, 6, 0, 3, 0, 0, 0, 1,3");
        console.log("需求分析2题计算结果:", newArray2);
    </script>
</body>
</html>